package com.ruoyi.material.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.material.domain.BaseFlieRecord;
import com.ruoyi.material.domain.BaseMaterial;
import com.ruoyi.material.domain.BaseTagFile;
import com.ruoyi.material.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
import java.util.List;

import com.ruoyi.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/material/imageDrawer")
public class DrawImageController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(DrawImageController.class);
    @Autowired
    private IBaseTagFileService baseTagFileService;
    @Autowired
    private IBaseMaterialService baseMaterialService;
    @Autowired
    private IBaseUpAndDownLoadService baseUpAndDownLoadService;
    @Autowired
    private IBaseFlieRecordService baseFlieRecordService;
    @Autowired
    private IDrawImageService drawImageService;
    /**
     * 查询标记文件信息列表
     */
//    @PreAuthorize("@ss.hasPermi('material:tag_file:list')")
    @GetMapping("/showPreview")
    public String list(BaseTagFile baseTagFile) throws IOException {
        logger.info("DrawImageController====list====【id值：{"+baseTagFile.getFileCode().intValue()+"}】");
        BaseMaterial baseMaterial = baseMaterialService.selectBMByFileCode(baseTagFile.getFileCode().intValue());
        baseTagFile.setFileCode(baseMaterial.getTabCode());
        List<BaseTagFile> list = baseTagFileService.selectBaseTagFileList(baseTagFile);
        BaseFlieRecord baseFlieRecord=baseFlieRecordService.selectBaseFlieRecordById(baseMaterial.getFileCode().longValue());
        String newImageUrl=drawImageService.drawImage(list,baseFlieRecord.getPathFileName(),baseFlieRecord.getOriginalFileName());//画图
        return newImageUrl;
    }
}
